﻿using System.ComponentModel.Composition;
using System.Windows.Controls;
using Caliburn.Micro;
using Scrabble.Model;
using Scrabble.ViewModels;

namespace Scrabble.Views
{
    public partial class PlayerView
    {
        public PlayerView()
        {
            InitializeComponent();

            IoC.BuildUp(this);

            EventLog.LoadingRow += OnLoadingRow;
        }

        [Import(typeof(IEventAggregator))]
        public IEventAggregator EventBroker { get; set; }

        private void OnLoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.MouseEnter += delegate
            {
                var wordPlay = e.Row.DataContext as IPlayWordEvent;
                if (wordPlay == null) return;
            
                EventBroker.Publish(new HotPlayingVectorChanged { TargetVector = wordPlay.PlayVector });
            };

            e.Row.MouseLeave += delegate
            {
                EventBroker.Publish(new HotPlayingVectorChanged());
            };
        }
    }
}
